//
//  LSZDynamicRealTimeSelectionVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/27.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZDynamicRealTimeSelectionVC.h"
#import "LSZDynamicRealTimeSelectionVC+LCCycle.h"

@interface LSZDynamicRealTimeSelectionVC ()<UINavigationControllerDelegate>
@property(nonatomic,strong)CustomHeaderView *titleHeaderView;
@property(nonatomic,strong) UIView * header;


@property(nonatomic,strong) UIView * typeDescriptionView;
@property(nonatomic,strong) UIView * typeDescriptionLab;
@end

@implementation LSZDynamicRealTimeSelectionVC

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton * butReturn = [[UIButton alloc]init];
    butReturn.frame = CGRectMake(0, STATUS_BAR_HEIGHT, 60, NAVIGATION_BAR_HEIGHT-STATUS_BAR_HEIGHT);
    [butReturn setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [butReturn addTarget:self action:@selector(clickButReturn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:butReturn];
    [self.view bringSubviewToFront:butReturn];
    self.tabPageController.tabBar.indicatorColor = redUIColor;
    [self.tabPageController.tabBar setIndicatorWidthFixTextAndMarginTop:self.tabPageController.tabBar.height-4 marginBottom:2 widthAdditional:-9 tapSwitchAnimated:true];
    self.tabPageController.tabBar.itemTitleFont = [LSZSpecialPackaging setlabelTextFontAdaptiveSize:15];//[UIFont systemFontOfSize:15];
    self.tabPageController.tabBar.indicatorScrollFollowContent = YES;
    [self initViewControllers];
    UIButton * butAdd =[[UIButton alloc]init];
    butAdd.frame = CGRectMake(3, ScreenHeight-TAB_BAR_HEIGHT-30-50, 50, 50);
    [butAdd setImage:[UIImage imageNamed:@"发布"] forState:UIControlStateNormal];
    [butAdd addTarget:self action:@selector(clickButPublishSpecificTypes) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:butAdd];
}
-(void)clickButPublishSpecificTypes
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }else{
        if([self.cname isEqualToString:@"祷告见证"]){
            LSZReleasePrayerAndWitnessVC * VC = [[LSZReleasePrayerAndWitnessVC alloc]init];
            VC.choosePosted = 1;
            VC.theme = self.theme;
            VC.themeStr = self.themeStr;
            VC.cname = self.cname;
            VC.kind = self.kind;
            [self.navigationController pushViewController:VC animated:YES];
        }else{
            LSZReleaseDynamicVC * VC = [[LSZReleaseDynamicVC alloc]init];
            VC.theme = self.theme;
            VC.themeStr = self.themeStr;
            VC.cname = self.cname;
            VC.kind = self.kind;
            [self.navigationController pushViewController:VC animated:YES];
        }
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offset=scrollView.contentOffset.y;
    if (offset <= 0) {
        scrollView.bounces = NO;
    }
    else{
        scrollView.bounces = YES;
    }
    if (iPhoneX) {
        if(offset >= self.headerView.frame.size.height-STATUS_BAR_HEIGHT-NAVIGATION_BAR_HEIGHT){
            self.scrollView.contentOffset = CGPointMake(0,self.headerView.frame.size.height-NAVIGATION_BAR_HEIGHT-STATUS_BAR_HEIGHT);//到导航的高度不滑动
        }
        CGFloat bifferenceBetween = self.headerView.frame.size.height-STATUS_BAR_HEIGHT-NAVIGATION_BAR_HEIGHT-offset;
        CGFloat transparency = bifferenceBetween/(self.headerView.frame.size.height-NAVIGATION_BAR_HEIGHT);
        if(transparency>0.6){
            self.typeDescriptionView.alpha = 0.6;
        }else{
            self.typeDescriptionView.alpha = transparency;
        }
        self.typeDescriptionLab.alpha = transparency;
    }else{
        if(offset >= self.headerView.frame.size.height-NAVIGATION_BAR_HEIGHT){
            self.scrollView.contentOffset = CGPointMake(0,self.headerView.frame.size.height-NAVIGATION_BAR_HEIGHT);//到导航的高度不滑动
        }
        CGFloat bifferenceBetween = self.headerView.frame.size.height-NAVIGATION_BAR_HEIGHT-offset;
        CGFloat transparency = bifferenceBetween/(self.headerView.frame.size.height-NAVIGATION_BAR_HEIGHT);
        if(transparency>0.6){
            self.typeDescriptionView.alpha = 0.6;
        }else{
            self.typeDescriptionView.alpha = transparency;
        }
        self.typeDescriptionLab.alpha = transparency;
    }
}
#pragma mark - 在此处添加滑动的图
- (UIView *)headerView {
    self.header  = [[UIView alloc] init];
    CGFloat height = [LSZSpecialPackaging initWithReturnsthesizeOf:210 :10];
    if (iPhoneX) {
        self.header.frame = CGRectMake(0,-STATUS_BAR_HEIGHT, ScreenWidth, height);
    }else{
        self.header.frame = CGRectMake(0, 0, ScreenWidth, height);
    }
    if (self.pagerView == nil) {
        [self loadDataWithPage:NO];
        [self.header addSubview:[self setupCycleWithCycleHeight:height]];
//        self.typeDescriptionView = [self loadViewBackTypeDescription:height];
        self.typeDescriptionLab = [self loadLabelTypeDescription:height];
        self.typeDescriptionView = [self loadViewBackTypeDescription:height];
        [self.header addSubview:self.typeDescriptionView];
        [self.header addSubview:self.typeDescriptionLab];
    }
    self.pagerView.tag = 10001;
    return self.header;
}
- (void)initViewControllers{
    NSMutableArray *vcArray = [NSMutableArray array];
    NSArray * array = @[@"最新",@"精选"];
    int i = 0;
    while (i<array.count) {
        LSZDynamicDetailsClassificationVC * controller = [[LSZDynamicDetailsClassificationVC alloc]init];
        controller.theme = NullStringjudgment(NSStr(self.theme));//话题id 从话题那进才有
        controller.kind = NullStringjudgment(NSStr(self.kind));
        if (i == 0) {
            controller.yp_tabItemTitle = [NSString stringWithFormat:@"%@",array[i]];
            controller.hot = @"";
            [vcArray addObject:controller];
        }
        else{
            controller.yp_tabItemTitle = [NSString stringWithFormat:@"%@",array[i]];
            controller.hot = @"1";
            [vcArray addObject:controller];
        }
        i++;
    }
    self.tabPageController.viewControllers = vcArray;
}
-(void)clickButReturn
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
#pragma mark - 弹出警告框
-(void)initWithString :(NSString *)string
{
    AlertKuangView * alert = [AlertKuangView new];
    [alert moveJingGaoKuang:string:self.view];
}
- (BOOL)prefersStatusBarHidden {
    return YES;
}
@end
